﻿import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
know_host = paramiko.AutoAddPolicy()
client.set_missing_host_key_policy(know_host)

client.connect(hostname='192.168.64.146', port=22, username='root', password='123456')
stdin, stdout, stderr = client.exec_command('pwd', get_pty=True, timeout=1)
# get_pty=True #可以同时执行多条命令
out = (stdout.read().decode('utf-8'))
status = stdout.channel
while not stdout.channel.exit_status_ready():
    result = stdout.readline()
    print(result)
    if stdout.channel.exit_status_ready():
        a = stdout.readlines()
        print(a)
        break
